/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modulemaker;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author takao
 */
public class Table {

  private List<Column> columns = new ArrayList<Column>();
  private String name;

  public Table(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public void addColumn(Column column) {
    columns.add(column);
  }

  public Column column(String name) {
    for (Iterator<Column> it = columns.iterator(); it.hasNext();) {
      Column column = it.next();
      if (column.getName().equals(name)) {
        return column;
      }
    }
    return null;
  }

  public List<Column> getColumns() {
    return Collections.unmodifiableList(columns);
  }

  public List<Column> getDisplayColumns() {
    List<Column> temp = new ArrayList<Column>();
    for (Iterator<Column> it = columns.iterator(); it.hasNext();) {
      Column column = it.next();
      
      if (column.getType() != Column.Type.PRIMARY_KEY) {
        temp.add(column);
      }
    }
    return Collections.unmodifiableList(temp);
  }
}
